import { fileURLToPath, URL } from 'node:url'
import { defineConfig } from 'vite'
import vue from '@vitejs/plugin-vue'
import fs from 'fs'
import path from 'path'
import { loadEnv } from 'vite'
// https://vitejs.dev/config/

export default defineConfig(({ mode }) => {
  const { VITE_APP_ACCESS_TOKEN, VITE_APP_BASE_URL, VITE_APP_PROJECT_ID, VITE_APP_FILE_URL } =
    loadEnv(mode, process.cwd())
  return {
    plugins: [vue()],
    resolve: {
      alias: {
        '@': fileURLToPath(new URL('./src', import.meta.url))
      }
    },
    define: {
      VITE_APP_BASE_URL: `'${VITE_APP_BASE_URL}'`,
      VITE_APP_ACCESS_TOKEN: `'${VITE_APP_ACCESS_TOKEN}'`,
      VITE_APP_PROJECT_ID: `'${VITE_APP_PROJECT_ID}'`,
      VITE_APP_FILE_URL: `'${VITE_APP_FILE_URL}'`
    },
    base: process.env.NODE_ENV === 'production' ? VITE_APP_BASE_URL : './',
    server: {
      host: '0.0.0.0',
      proxy: {
        '/datav-3d-web': {
          target: 'http://10.10.10.6:8025/',
          changeOrigin: true,
          secure: false
          // rewrite: path => path.replace(/^\/api/, '')
        }
      }
    }
  }
})
